<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="author" content="得闲技术 Team">
    <meta name="copyright" content="得闲技术">
    <title>管理中心主页 - Powered By 得闲技术</title>
    <link href="${base}/resources/favicon.ico" rel="icon">
    <link href="${base}/resources/common/css/bootstrap.css" rel="stylesheet">
    <link href="${base}/resources/common/css/iconfont.css" rel="stylesheet">
    <link href="${base}/resources/common/css/iconfont1.css" rel="stylesheet">
    <link href="${base}/resources/common/css/font-awesome.css" rel="stylesheet">
    <link href="${base}/resources/common/css/bootstrap-select.css" rel="stylesheet">
    <link href="${base}/resources/common/css/ajax-bootstrap-select.css" rel="stylesheet">
    <link href="${base}/resources/common/css/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${base}/resources/common/css/bootstrap-fileinput.css" rel="stylesheet">
    <link href="${base}/resources/common/css/base.css" rel="stylesheet">
    <link href="${base}/resources/admin/css/base.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="${base}/resources/common/js/html5shiv.js"></script>
    <script src="${base}/resources/common/js/respond.js"></script>
    <![endif]-->
    <script src="${base}/resources/common/js/jquery.js"></script>
    <script src="${base}/resources/common/js/bootstrap.js"></script>
    <script src="${base}/resources/common/js/bootstrap-growl.js"></script>
    <script src="${base}/resources/common/js/bootstrap-select.js"></script>
    <script src="${base}/resources/common/js/ajax-bootstrap-select.js"></script>
    <script src="${base}/resources/common/js/bootstrap-fileinput.js"></script>
    <script src="${base}/resources/common/js/jquery.nicescroll.js"></script>
    <script src="${base}/resources/common/js/jquery.validate.js"></script>
    <script src="${base}/resources/common/js/jquery.validate.additional.js"></script>
    <script src="${base}/resources/common/js/jquery.form.js"></script>
    <script src="${base}/resources/common/js/jquery.cookie.js"></script>
    <script src="${base}/resources/common/js/lodash.js"></script>
    <script src="${base}/resources/common/js/URI.js"></script>
    <script src="${base}/resources/common/js/base.js"></script>
    <script src="${base}/resources/admin/js/base.js"></script>
</head>
[#include "/admin/main/header.ftl" /]
[#include "/admin/main/aside.ftl" /]
<body class="admin">
<main>
    <iframe width="100%" height="800" src="${base}/admin/main" id="mainFrameContent" name="mainFrameContent"
            frameborder="0"></iframe>
</main>
<script>
    $().ready(function () {
        var $logoutForm = $("#logoutForm");
        var $mainHeaderLogout = $("#mainHeaderLogout");

        $mainHeaderLogout.click(function () {
            $logoutForm.submit();
        });

        var $window = $(window);
        var $body = $("body");
        var $mainSidebarCollapseToggle = $("[data-toggle='mainSidebarCollapse']");
        var $mainSidebar = $("#mainSidebar");
        var $searchForm = $("#mainSidebar .search form");
        var $searchValue = $("#mainSidebar .search input[name='searchValue']");
        var $panelCollapse = $("#mainSidebar .panel-collapse");

        var $mainFrameContent = $("#mainFrameContent");
        var iframeHeight = $window.height() - 75;

        $mainFrameContent.attr("height", iframeHeight + "px");

        $window.resize(function () {
            iframeHeight = $window.height() - 75;
            $mainFrameContent.attr("height", iframeHeight + "px");
        });

        // 主侧边栏折叠
        $mainSidebarCollapseToggle.click(function () {
            var niceScroll = $mainSidebar.getNiceScroll();
            var interval = setInterval(function () {
                niceScroll.resize();
            }, 10);

            if ($window.width() > 767) {
                $body.removeClass("main-sidebar-expanded").toggleClass("main-sidebar-mini");
            } else {
                $body.removeClass("main-sidebar-mini").toggleClass("main-sidebar-expanded");
            }

            $body.one("bsTransitionEnd", function () {
                niceScroll.resize();
                window.clearInterval(interval);
            }).emulateTransitionEnd(500);
        });

        // 主侧边栏滚动条
        $mainSidebar.niceScroll({
            cursorwidth: "4px",
            cursorcolor: "#ffffff",
            cursorborder: "0px",
            cursoropacitymax: 0.4
        });

        // 搜索
        $searchForm.submit(function () {
            var $form = $(this).closest("form");
            var searchValue = $searchValue.val();

            if ($.trim(searchValue) === "") {
                return false;
            }
            $form.append('<input name="name" type="hidden" value="' + searchValue + '">');
        });

        // 面板折叠
        $panelCollapse.on("shown.bs.collapse hidden.bs.collapse", function () {
            $mainSidebar.getNiceScroll().resize();
        });

        var $listGroupItem = $(".list-group-item");

        $listGroupItem.click(function () {
            $listGroupItem.removeClass("active");
            $(this).addClass("active");

            let index = $(this).index();
            let parentId = $(this).closest("div.panel-collapse").attr("id");
            $.cookie("rememberAside", index+ "," + parentId, {expires:30});
        });

        $(".panel").each(function () {
            let size = $(this).find("li.list-group-item").size();

            if (size === 0) {
                $(this).addClass("hidden")
            }
        });

       let rememberAside = $.cookie("rememberAside");

       if(rememberAside != null){
           let arr = rememberAside.split(",");
           let index = arr[0];
           let parentId = arr[1];

           let $parent = $("#" + parentId);

           $parent.find("li").each(function(i){
               if(i == index){
                   $(this).addClass("active");
               }
           });
           $parent.addClass("in");
       }

    });
</script>
[#include "/admin/template/csrf.ftl" /]
</body>
</html>
